package com.dtsz.m2.ui.adapter;

import android.content.Context;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dtsz.m2.R;
import com.dtsz.m2.refresh.baseadapter.CommonAdapter;
import com.dtsz.m2.refresh.baseadapter.ViewHolder;
import com.dtsz.m2.ui.inter.OnGetInputFinish;
import com.dtsz.m2.ui.model.MwRecordVo;
import com.dtsz.m2.volley.commonadapter.BaseCommonAdapter;

import java.util.List;


public class MeadWallAdatper extends BaseCommonAdapter {
    private Context myContext;
    private OnGetInputFinish onGetInputFinish;

    public MeadWallAdatper(Context context, List data, int layoutItemId, OnGetInputFinish onGetInputFinish) {
        super(context, data, layoutItemId);
        this.myContext = context;
        this.onGetInputFinish = onGetInputFinish;
    }

    @Override
    public void convertView(com.dtsz.m2.volley.commonadapter.ViewHolder holder, Object o) {
        MwRecordVo mwRecordVo = (MwRecordVo) o;
        Glide.with(myContext).load(mwRecordVo.getLightUrl()).into((ImageView) holder.getChildView(R.id.iv_url));
        holder.setTextView(R.id.tv_title, mwRecordVo.getName());
        holder.setTextView(R.id.tv_num, "(" + mwRecordVo.getMwrNum() + "/" + mwRecordVo.getNumber() + ")");
        holder.setTextView(R.id.tv_explain, (SpannableStringBuilder) Html.fromHtml(mwRecordVo.getExplain()));

        String status = mwRecordVo.getStatus();
        TextView tvClick = holder.getChildView(R.id.tv_click);
        switch (status) {
            case "1":
                String reward = mwRecordVo.getReward();
                if ("0".equals(reward)) {
                    tvClick.setVisibility(View.GONE);
                } else {
                    tvClick.setVisibility(View.VISIBLE);
                }
                tvClick.setOnClickListener(null);
                tvClick.setText("+"+mwRecordVo.getReward() + "㎡");
                tvClick.setBackgroundResource(R.drawable.radius20_blue);
                break;
            case "2":
//                holder.setOnClickListener(R.id.tv_click, new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        onGetInputFinish.getInputFinish(mwRecordVo);
//                    }
//                });
                tvClick.setVisibility(View.VISIBLE);
                tvClick.setText("领取");
                tvClick.setBackgroundResource(R.drawable.radius20_huangse);
                tvClick.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        onGetInputFinish.getInputFinish(mwRecordVo);
                    }
                });
                break;
            case "3":
                tvClick.setOnClickListener(null);
                tvClick.setVisibility(View.VISIBLE);
                tvClick.setBackgroundResource(R.drawable.radius20_huise);
                tvClick.setText("未完成");
                break;
        }


    }
}
